package com.yiren.dbaa.module.practice_set.basestation.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;

import com.yiren.backstage.currency.utils.DateUtil;
import com.yiren.dbaa.R;
import com.yiren.dbaa.activity.BaseActivity;
import com.yiren.dbaa.module.practice_set.basestation.bean.BaseStationBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author lwb
 * @date : 2022/12/13 9:19
 * @description: 基站详情页
 */
public class BaseStationDetailActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_base_id)
    TextView tvBaseId;
    @BindView(R.id.tv_base_name)
    TextView tvBaseName;
    @BindView(R.id.tv_base_location)
    TextView tvBaseLocation;
    @BindView(R.id.tv_calibration_state)
    TextView tvCalibrationState;
    @BindView(R.id.tv_create_time)
    TextView tvCreateTime;
    @BindView(R.id.tv_coordinate)
    TextView tvCoordinate;
    @BindView(R.id.tv_offline_time)
    TextView tvOfflineTime;
    @BindView(R.id.tv_online_time)
    TextView tvOnlineTime;
    @BindView(R.id.tv_packet_time)
    TextView tvPacketTime;
    @BindView(R.id.tv_connect_number)
    TextView tvConnectNumber;

    private Intent intent;
    private BaseStationBean baseStationBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basestation_detail);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        tvTitle.setText("基站详情");
        intent = getIntent();
        baseStationBean = (BaseStationBean) intent.getSerializableExtra("baseStation");
        if (baseStationBean != null) {
            tvBaseId.setText(baseStationBean.getId());
            tvBaseName.setText(baseStationBean.getName());
            tvBaseLocation.setText(baseStationBean.getAddress());
            tvCalibrationState.setText(baseStationBean.getCalibration() == 1 ? "已标定" : "未标定");
            tvCreateTime.setText(DateUtil.longTimeToString(baseStationBean.getCreateTm()));
            tvCoordinate.setText(baseStationBean.getLongitude() + "/" + baseStationBean.getLatitude());
            tvOfflineTime.setText(DateUtil.longTimeToString(baseStationBean.getOfflineTm()));
            tvOnlineTime.setText(DateUtil.longTimeToString(baseStationBean.getOnlineTm()));
            tvPacketTime.setText(DateUtil.longTimeToString(baseStationBean.getPacketReceivedTm()));
            tvConnectNumber.setText(baseStationBean.getConnectNumber() + "");
        }
    }

    @OnClick(R.id.iv_back)
    public void onClick() {
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }
}
